// 1.导入http模块
const http = require('http');
const fs = require('fs');
//2.创建服务对象
const server = http.createServer((request,response)=>{
    let {pathname} = new URL(request.url,'http://192.168.101.159');
    let html = fs.readFileSync('../resource/test.html');
    let css = fs.readFileSync('../resource/test.css');
    let jsFile = fs.readFileSync('../resource/test.js');
    if(pathname === '/') {
        response.end(html);//设置响应体
    }else if(pathname === '/resource/test.css') {
        response.end(css);//设置响应体
    }else if(pathname === '/resource/test.js') {
        response.end(jsFile);//设置响应体
    }else{
        response.statusCode = 404;
        response.end('Not Found');//设置响应体
    }
})
// 3.监听端口，启动服务
server.listen(9000,()=>{
    console.log('服务已经启动。。。端口9000监听中。。。。');
})